package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.entity.StudentInfo;
import com.five.wisdomEat.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentService {
    @Autowired
    private StudentMapper mapper;
    public ResponseMessage selectStudentList(){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectStudentList());
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage insertStudent(StudentInfo studentInfo){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertStudent(studentInfo)>0?true:false;
        if(flag){
            message.setMessage("添加成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("添加失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage updateStudent(StudentInfo studentInfo){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.updateStudent(studentInfo)>0?true:false;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage deleteStudent(String sNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.deleteStudent(sNumber)>0?true:false;
        if(flag){
            message.setMessage("删除成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("删除失败");
            message.setSuccess(flag);
        }
        return message;
    }
}
